#ifndef BYOGAME_H
#define BYOGAME_H

#include "byogamebase.h"
#include <wx/string.h>
#include <wx/dynarray.h>
#include <wx/intl.h>
#include <editorbase.h>

#define BYO_REGISTER_GAME(ClassName,GameName) \
  namespace { \
    class ClassName##_Launcher: public GameLauncher { \
      public:\
        ClassName##_Launcher(): GameLauncher(_(GameName)) {}\
      protected:\
        virtual void Play() {\
          byoEditorBase* base = new byoEditorBase(_(GameName));\
          base->AddGameContent(new ClassName(base,_(GameName)));\
        }\
    } ClassName##_Launcher_Instance;\
  }

class GameLauncher {
  public:
    GameLauncher( const wxString& Name );
    virtual ~GameLauncher();
    static inline int GetGamesCount() { return ( int )GetGames().Count(); }
    static inline const wxString& GetGameName( int gameNum ) { return GetGames()[gameNum]->m_Name; }
    static inline void PlayGame( int gameNum ) { GetGames()[gameNum]->Play(); }
  protected:
    virtual void Play() = 0;
  private:
    WX_DEFINE_ARRAY( GameLauncher*, GamesT );
    wxString m_Name;
    static GamesT& GetGames();
};

class byoEditorBase: public EditorBase {
  public:
    byoEditorBase( const wxString& GameName );
    virtual ~byoEditorBase();
    void AddGameContent( GameBase* base );
    virtual void Activate() { if( m_Content ) m_Content->SetFocus(); EditorBase::Activate(); }
  private:
    void OnSetFocus( wxFocusEvent& ) { if( m_Content ) m_Content->SetFocus(); }
    GameBase* m_Content;
    DECLARE_EVENT_TABLE()
};

#endif
